<?php
/**
 * @Notes:【】
 * @User: zwc
 * @Date: 2022-05-04 13:31
 */

namespace App\Controller\Api\Task;

use App\Controller\User\BaseController;
use App\Dao\Task\TaskBlacklistDao;
use App\Middleware\GetAuthTokenMiddleware;
use App\Service\Task\TaskReceiveService;
use App\Service\Task\TaskService;
use App\Service\User\UserService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Middleware;
use Yj\Apidog\Annotation\ApiController;
use Yj\Apidog\Annotation\FormData;
use Yj\Apidog\Annotation\PostApi;

/**
 * @Notes:【】
 * @User: zwc
 * @Date: 2022-05-04 13:31
 * @Middleware(GetAuthTokenMiddleware::class)
 * @ApiController(prefix="api/task/task")
 */
class TaskController extends BaseController
{
    /**
     * @Inject()
     * @var TaskService
     */
    protected $taskService;

    /**
     * @Inject()
     * @var UserService
     */
    protected $userService;

    /**
     * @Inject()
     * @var TaskReceiveService
     */
    protected $taskReceiveService;

    /**
     * @Notes:【】
     * @Date: 2022-05-31 1:17
     * @PostApi(path="getTaskDetail")
     * @FormData(key="user_id",rule="Required")
     */
    public function getTaskDetail()
    {
        $userID = $this->getValidatorData('user_id');
        $userInfo = $this->userService->getUserInfo($userID);
        $taskStatis = $this->taskService->getTaskStatic($userID);
        _SUCCESS(compact('userInfo', 'taskStatis'));
    }

    /**
     * @Notes:【】
     * @Date: 2022-09-26 22:54
     * @PostApi(path="hot")
     */
    public function hot()
    {
        $data = $this->taskReceiveService->page(false)->hot();
        _SUCCESS($data);
    }

    /**
     * @Notes:【列表】
     * @User: zwc
     * @Date: 2022-05-04 13:32
     * @PostApi(path="lists")
     * @FormData(key="types",rule="Required")
     * @FormData(key="user_id",rule="nullable")
     * @FormData(key="sort",rule="nullable")
     * @FormData(key="task_types_id",rule="nullable")
     * @FormData(key="title",rule="nullable")
     */
    public function lists()
    {
        $params = $this->getValidatorData();
        $params->offsetSet('status', 2);
        if (empty($params->get('sort'))) {
            $params->offsetSet('sort', ['top_time', 'refresh_time', 'id']);
        } else {
            $params->offsetSet('sort', [$params->get('sort')]);
        }
        $user_id = $this->getUid();

        $black_task_id = app(TaskBlacklistDao::class)->getBlacklist($user_id);
        dump($black_task_id);

        $params->offsetSet('black_task_id', $black_task_id);
        $data = $this->taskService->lists($params);
        _SUCCESS($data);
    }

    /**
     * @Notes:【】
     * @Date: 2022-06-06 22:53
     * @PostApi(path="recomment")
     */
    public function recomment()
    {
        $data = $this->taskService->lists(_Collect(['is_recomment' => 1, 'status' => 2]));
        _SUCCESS($data);
    }


    /**
     * @Notes:【】
     * @User: zwc
     * @Date: 2022-05-06 22:09
     * @PostApi(path="types")
     */
    public function types()
    {
        $data = $this->taskService->page(false)->getTypes();
        _SUCCESS($data);
    }

}